import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    title: '昵称',
    dataIndex: 'nickname',
    width: 120,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 180,
  },
  {
    title: '留言内容',
    dataIndex: 'content',
    width: 300,
    key: 'content',
  },
  {
    title: 'IP地址',
    dataIndex: 'ipAddress',
    width: 120,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 100,
    key: 'status',
    customRender: ({ record }) => {
      const statusMap = {
        0: { text: '待审核', color: 'orange' },
        1: { text: '已发布', color: 'green' },
        2: { text: '已拒绝', color: 'red' },
      };
      const status = statusMap[record.status] || { text: '未知', color: 'default' };
      return h(Tag, { color: status.color }, () => status.text);
    },
  },
  {
    title: '回复数量',
    dataIndex: 'replyCount',
    width: 100,
  },
  {
    title: '点赞数量',
    dataIndex: 'likeCount',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createdTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'nickname',
    label: '昵称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'email',
    label: '邮箱',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '待审核', value: 0 },
        { label: '已发布', value: 1 },
        { label: '已拒绝', value: 2 },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'nickname',
    label: '昵称',
    component: 'Input',
    required: true,
  },
  {
    field: 'email',
    label: '邮箱',
    component: 'Input',
    required: true,
    rules: [
      {
        type: 'email',
        message: '请输入正确的邮箱格式',
      },
    ],
  },
  {
    field: 'content',
    label: '留言内容',
    component: 'InputTextArea',
    required: true,
    componentProps: {
      rows: 4,
      maxlength: 500,
      showCount: true,
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '待审核', value: 0 },
        { label: '已发布', value: 1 },
        { label: '已拒绝', value: 2 },
      ],
    },
  },
]; 